import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/api/http_api.dart';

import '../../net/response/work_schedule_plan_data.dart';

class WorkScheduleModel extends BaseMvvmModel {
  @override
  void onCleared() {}


  Future<Map> getPlanDetail(String month,dynamic humanId) async {
    var map = {
      "month":month,
      "humanId":humanId,
    };
    var url = "${HttpApi.baseUrl}schedulingRecord/detailRecord";
    var data = await HttpGo.instance.getData(url, data: map);
    if("0"==data['code']){
      return data['data']['map'];
    }else{
      throw data['msg'];
    }
  }

  Future<List<WorkSchedulePlanData>> getPlanData(String month) async {
    var map = {
      "wrapper": true,
      "month": month,
      "isAppRequest": true,
      "scheduingStatus": 1,
    };

    var data = await HttpGo.instance.getData(HttpApi.schedulingPlan, data: map);
    if ('0' == data['code']) {
      var dataList = ((data['data']['headers'] as List) ?? [])
          .map((e) => WorkSchedulePlanData.fromJson(e))
          .toList();

      var staffList = (data['data']['staffList'] as List)??[];
      if(staffList.isNotEmpty){
        for(var data in dataList){
          data.status = staffList[0][data.prop]??"";
        }
      }
      return dataList;
    } else {
      throw data['msg'];
    }
  }
}
